<?php

/**
 * weapon actions.
 *
 * @package    aiontoolskit
 * @subpackage weapon
 * @author     Your name here
 * @version    SVN: $Id: actions.class.php 23810 2009-11-12 11:07:44Z Kris.Wallsmith $
 */
class weaponActions extends sfActions
{
  public function executeIndex(sfWebRequest $request)
  {
  	$max = sfConfig::get('app_items_per_page');
    $this->pager = new sfDoctrinePager('GameWeapon', $max);
    $this->pager->setQuery(Doctrine_Core::getTable('GameWeapon')->getWeaponsQuery($max));
    $this->pager->setPage($request->getParameter('page', 1));
    $this->pager->init();
  }

  public function executeShow(sfWebRequest $request)
  {
    $this->weapon = $this->getRoute()->getObject();
  }

  public function executeNew(sfWebRequest $request)
  {
    $this->form = new GameWeaponForm();
  }

  public function executeCreate(sfWebRequest $request)
  {
    $this->forward404Unless($request->isMethod(sfRequest::POST));

    $this->form = new GameWeaponForm();

    $this->processForm($request, $this->form);

    $this->setTemplate('new');
  }

  public function executeEdit(sfWebRequest $request)
  {
    $this->forward404Unless($game_weapon = Doctrine_Core::getTable('GameWeapon')->find(array($request->getParameter('id'))), sprintf('Object game_weapon does not exist (%s).', $request->getParameter('id')));
    $this->form = new GameWeaponForm($game_weapon);
  }

  public function executeUpdate(sfWebRequest $request)
  {
    $this->forward404Unless($request->isMethod(sfRequest::POST) || $request->isMethod(sfRequest::PUT));
    $this->forward404Unless($game_weapon = Doctrine_Core::getTable('GameWeapon')->find(array($request->getParameter('id'))), sprintf('Object game_weapon does not exist (%s).', $request->getParameter('id')));
    $this->form = new GameWeaponForm($game_weapon);

    $this->processForm($request, $this->form);

    $this->setTemplate('edit');
  }

  public function executeDelete(sfWebRequest $request)
  {
    $request->checkCSRFProtection();

    $this->forward404Unless($game_weapon = Doctrine_Core::getTable('GameWeapon')->find(array($request->getParameter('id'))), sprintf('Object game_weapon does not exist (%s).', $request->getParameter('id')));
    $game_weapon->delete();

    $this->redirect('weapon/index');
  }

  protected function processForm(sfWebRequest $request, sfForm $form)
  {
    $form->bind($request->getParameter($form->getName()), $request->getFiles($form->getName()));
    if ($form->isValid())
    {
      $game_weapon = $form->save();

      $this->redirect('weapon/edit?id='.$game_weapon->getId());
    }
  }
}
